#-*- codeing = utf-8 -*-
#@Time : 2020/11/14 15:31
#@Author : 阳某
#@File : my_socket_web.py
#@Software : PyCharm



import socket

def main():
    sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
    sock.bind(('localhost',8000))
    sock.listen(5)
    while True:
        # 等待浏览器访问
        conn,addr = sock.accept()
        # 接收浏览器发送的请求内容
        data = conn.recv(1024)
        print(data)

        # 给浏览器返回内容
        conn.send(b'HTTP/1.1 200 OK\r\nContent-Type:text/html;charset=utf-8\r\n\r\n')
        conn.send('<h1 style="color:red">电脑前的你长得真漂亮！</h1>'.encode('utf-8'))

        # 关闭浏览器创建的socket连接
        conn.close()
if __name__ == '__main__':
    main()